package com.example.consumer.controller;

import com.example.consumer.feign.FeignService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * 描述
 *
 * @author Huzz
 * @create 2022-07-14 17:19
 */
@RestController
public class NacosConsumerController {

//    @Autowired
//    private LoadBalancerClient loadBalancerClient;

//    @Autowired
//    private RestTemplate restTemplate;
//
//    @Value("${spring.application.name}")
//    private String appName;

//    @GetMapping(value = "/test/app/name")
//    public String test() {
//        //使用 LoadBalanceClient 和 RestTemplate 结合的方式来访问
//        ServiceInstance serviceInstance = loadBalancerClient.choose("server-provider");
//        String url = String.format("http://%s:%s/test/%s", serviceInstance.getHost(), serviceInstance.getPort(), appName);
//        return restTemplate.getForObject(url, String.class);
//    }

    @Autowired
    private FeignService feignService;

    @GetMapping(value = "/test/hi")
    public String test() {
        return feignService.test("Hi Feign");
    }

}
